package prototypePatter1;

import cn.hutool.core.util.ObjectUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 582895699@qq.com
 * @Desctription: TODO
 * @Date: Created in 2021/12/16 17:28
 */
public class Things implements Cloneable, Serializable {

    private static final long serialVersionUID = 5789221652470569669L;
    private List<String> list = new ArrayList<>();

    public void setValue(String item) {
        this.list.add(item);
    }

    public List<String> getList() {
        return this.list;
    }

    @Override
    protected Things clone() throws CloneNotSupportedException {
        Things things = null;
        try {
            things = (Things) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return things;
    }

    public static void main(String[] args) {
        Things things = new Things();
        things.setValue("123");
        Things clone = ObjectUtil.cloneByStream(things);
        clone.setValue("456");

        System.out.println(things.getList());
        System.out.println(clone.getList());
    }
}
